package com.iman.manjusri.web.home;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.iman.common.support.Page;
import com.iman.manjusri.service.HomeHyService;
import com.iman.manjusri.vo.HomeVo;
import com.iman.manjusri.web.BaseController;

@Controller
@RequestMapping(value = "/home/*")
public class SpaceHyHomController extends BaseController {

	@Autowired
	HomeHyService homeHyService;

	@RequestMapping(value = "/hy")
	public ModelAndView hy(HttpServletRequest request) throws Exception {

		Map<String, Object> model = new HashMap<String, Object>();
		int operType = NumberUtils.toInt(request.getParameter("operType"), 1);
		int ps = NumberUtils.toInt(request.getParameter("ps"), 10); // 每页多少条记录
		int pn = NumberUtils.toInt(request.getParameter("pn"), 1); // 第几页

		Page<HomeVo> pageDatas = homeHyService.getHome(operType, ps, pn);

		model.put("pageData", pageDatas);

		ModelAndView view = null;
		if(operType == 1){
			view = new ModelAndView("home/hy", model);
		}else if(operType == 2){
			view = new ModelAndView("home/js",model);
		}else if(operType == 3){
			view = new ModelAndView("home/zx",model);
		}

		putResourceSrc(view);
		return view;
	}

}
